######################
## Dockerfile to build container images consisting of Node.js and nginx environment
# Based on Ubuntu
#####

# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
# MAINTAINER name Chunteng Xiao
RUN apt-get clean
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update
RUN apt-get -f install -y curl unzip wget tar
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN apt-get install -y oracle-java8-installer 
RUN apt-get install -y oracle-java8-set-default
ADD ./sonar-scanner-cli-3.2.0.1227-linux.zip ./sonarscanner.zip
RUN unzip sonarscanner.zip
RUN rm sonarscanner.zip
ENV SONAR_RUNNER_HOME=/sonar-scanner-3.2.0.1227-linux
ENV PATH $PATH:/sonar-scanner-3.2.0.1227-linux/bin
RUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-9/v9.0.12/bin/apache-tomcat-9.0.12.tar.gz
RUN tar xzf apache-tomcat-9.0.12.tar.gz
RUN mv apache-tomcat-9.0.12 apache-tomcat9
RUN wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
RUN tar xzvf apache-maven-3.5.4-bin.tar.gz
RUN ln -s apache-maven-3.5.4 apache-maven
ENV M2_HOME=//apache-maven
ENV CATALINA_HOME=/apache-tomcat9
ENV TOMCAT_HOME=/apache-tomcat9
ENV MAVEN_HOME=/apache-maven
ENV PATH=${M2_HOME}/bin:${PATH}
ENV JAVA_HOME=/usr/lib/jvm/java-8-oracle
ENV JRE_HOME=/usr/lib/jvm/java-8-oracle/jre
ADD ca.crt ./
COPY ./additional_jars ./additional_jars
COPY tomcat-users.xml ${CATALINA_HOME}/conf/tomcat-users.xml
COPY context.xml ${CATALINA_HOME}/webapps/manager/META-INF/context.xml
RUN keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias maven2.ca -file ca.crt
RUN keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias maven2.ca -file ca.crt
RUN mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.2.0.1.0 -Dpackaging=jar -Dfile=./additional_jars/ojdbc7.jar
COPY sonar-runner.properties ./sonar-scanner-3.2.0.1227-linux/conf/sonar-scanner.properties
EXPOSE 84
EXPOSE 8080